<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix" style="text-align: center;line-height: 30px">
        <h3>修改供应商信息</h3>
      </div>
      <div class="text item">
        <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-row>
            <el-form-item label="供应商名称" prop="name">
              <el-input v-model="ruleForm.name" style="border: none"></el-input>
            </el-form-item>
          </el-row>
          <br>
          <el-row>
            <el-form-item label="负责人" prop="name">
              <el-input v-model="ruleForm.mainperson"></el-input>
            </el-form-item>
          </el-row>
          <br>
          <el-row>
            <el-form-item label="负责人电话" prop="name">
              <el-input v-model="ruleForm.tel"></el-input>
            </el-form-item>
          </el-row>
          <br>
          <el-row>
            <el-form-item label="供应商地址" prop="name">
              <el-input v-model="ruleForm.address" style="border: none"></el-input>
            </el-form-item>
          </el-row>
          <br>
          <el-row>
            <el-form-item label="经营范围">
              <el-input type="textarea" v-model="ruleForm.scope" style="border: none"></el-input>
            </el-form-item>
          </el-row>
          <br>

          <el-row>
            <div style="text-align: center">
              <el-form-item>
                <el-button type="primary" @click="update">修改</el-button>
              </el-form-item>
            </div>
          </el-row>
        </el-form>
      </div>
    </el-card>

  </div>
</template>

<script>
export default {
  name: "UpdateProvider",
  props: {
    buyId:JSON
  },
  data(){
    return{
      ruleForm:{
        name:'',
        mainperson:'',
        tel:'',
        address:'',
        scope:''
      }
    }
  },
  mounted() {
    this.init()
  },
  methods:{
    init(){
      console.log(this.buyId)
      let url = 'apj/provider/selectOneProvider/'+this.buyId.providerName
      this.$axios.get(url).then(r=>{
        let datas = r.data
        this.ruleForm.name = datas.providerName
        this.ruleForm.mainperson = datas.mainPerson
        this.ruleForm.tel = datas.mainpersonTel
        this.ruleForm.address = datas.providerAddress
        this.ruleForm.scope = datas.providerScope
      })
    },
    update() {
      let url = 'apj/provider/updateProvider'
      let fd = new FormData
      fd.append("providerName",this.ruleForm.name)
      fd.append("mainPerson",this.ruleForm.mainperson)
      fd.append("mainpersonTel",this.ruleForm.tel)
      fd.append("providerAddress",this.ruleForm.address)
      fd.append("providerScope",this.ruleForm.scope)
      this.$axios.post(url,fd).then(r=>{
        // eslint-disable-next-line no-unused-vars
        let user = r.data
        this.$message.success(user)
        this.$emit("init")
        this.$emit("close")
      })
    }
  }
}
</script>

<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

</style>